/**
 * 将项目按文件名排序
 */

const vscode = require('vscode');
const util = require('../util');

module.exports = function(context) {
    context.subscriptions.push(vscode.commands.registerCommand('extension.sortWorkspace', function () {
        const workspaceFolders = vscode.workspace.workspaceFolders;
        if (workspaceFolders.length <= 1) return;
        // 按文件名升序排序
        const newFolders = vscode.workspace.workspaceFolders.sort((a, b) => {
            return a.name === b.name ? 0 : (a.name < b.name ? -1 : 1);
        });
        vscode.workspace.updateWorkspaceFolders(0, workspaceFolders.length, ...newFolders);
        util.showInfo('按文件名排序成功！');
    }));
};